import { createRouter, createWebHistory } from 'vue-router'

// 路由配置
const routes = [
  // 登录和用户相关路由
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/auth/Login.vue'),
    meta: { 
      title: '登录',
      requiresAuth: false
    }
  },
  // 前台登录路由
  {
    path: '/front/login',
    name: 'FrontLogin',
    component: () => import('@/views/front/auth/FrontLogin.vue'),
    meta: { 
      title: '用户登录',
      requiresAuth: false
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('@/views/auth/Profile.vue'),
    meta: { 
      title: '个人信息',
      requiresAuth: true
    }
  },
  
  // 前台活动路由 - 使用FrontLayout布局
  {
    path: '/',
    component: () => import('@/views/front/layout/FrontLayout.vue'),
    meta: { 
      requiresAuth: false
    },
    children: [
      // 根路径直接显示活动列表
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/front/event/List.vue'),
        meta: { 
          title: '活动列表', 
          requiresAuth: false,
          allowAnonymous: true // 明确允许匿名访问
        }
      },
      {
        path: 'front/event/list',
        name: 'FrontEventList',
        component: () => import('@/views/front/event/List.vue'),
        meta: { 
          title: '活动列表', 
          requiresAuth: false
        }
      },
      {
        path: 'front/event/detail/:id',
        name: 'FrontEventDetail',
        component: () => import('@/views/front/event/Detail.vue'),
        meta: { 
          title: '活动详情', 
          requiresAuth: false
        }
      },
      // 前台个人中心 - 需要前台登录
      {
        path: 'front/user/profile',
        name: 'FrontUserProfile',
        component: () => import('@/views/front/user/Profile.vue'),
        meta: { 
          title: '个人中心', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      // 订单相关路由
      {
        path: 'front/order/create',
        name: 'FrontOrderCreate',
        component: () => import('@/views/front/order/CreateOrder.vue'),
        meta: { 
          title: '创建订单', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      {
        path: 'front/order/pay',
        name: 'FrontOrderPay',
        component: () => import('@/views/front/order/PayOrder.vue'),
        meta: { 
          title: '订单支付', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      
      // 用户中心 - 订单和电子票
      {
        path: 'front/user/orders',
        name: 'FrontUserOrders',
        component: () => import('@/views/front/user/OrderList.vue'),
        meta: { 
          title: '我的订单', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      {
        path: 'front/user/order-detail',
        name: 'FrontUserOrderDetail',
        component: () => import('@/views/front/user/OrderDetail.vue'),
        meta: { 
          title: '订单详情', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      {
        path: 'front/user/tickets',
        name: 'FrontUserTickets',
        component: () => import('@/views/front/user/TicketList.vue'),
        meta: { 
          title: '我的电子票', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      {
        path: 'front/user/ticket-detail',
        name: 'FrontUserTicketDetail',
        component: () => import('@/views/front/user/TicketDetail.vue'),
        meta: { 
          title: '电子票详情', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      },
      {
        path: 'front/questionnaire/:eventId',
        name: 'FrontQuestionnaire',
        component: () => import('@/views/front/questionnaire/FillQuestionnaire.vue'),
        meta: { 
          title: '填写问卷', 
          requiresAuth: false,
          requiresFrontAuth: true // 需要前台登录
        }
      }
    ]
  },
  
  // 活动管理路由
  {
    path: '/event',
    component: () => import('@/views/event/List.vue'),
    name: 'EventList',
    meta: { 
      title: '活动列表', 
      requiresAuth: true
    }
  },
  {
    path: '/event/detail/:id',
    component: () => import('@/views/event/Detail.vue'),
    name: 'EventDetail',
    meta: { 
      title: '活动详情', 
      requiresAuth: true
    }
  },
  {
    path: '/event/create',
    component: () => import('@/views/event/Edit.vue'),
    name: 'EventCreate',
    meta: {
      title: '创建活动',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  {
    path: '/event/edit/:id',
    component: () => import('@/views/event/Edit.vue'),
    name: 'EventEdit',
    meta: {
      title: '编辑活动',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  {
    path: '/event/report/:id',
    component: () => import('@/views/report/EventReport'),
    name: 'EventReport',
    meta: {
      title: '活动统计',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  
  // 票种管理路由
  {
    path: '/ticket',
    name: 'TicketList',
    component: () => import('@/views/ticket/List.vue'),
    meta: {
      title: '票种管理',
      requiresAuth: true
    }
  },
  
  // 用户管理路由
  {
    path: '/user',
    name: 'UserList',
    component: () => import('@/views/user/List.vue'),
    meta: {
      title: '用户管理',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  
  // 会话管理路由
  {
    path: '/session/online',
    name: 'OnlineUsers',
    component: () => import('@/views/session/Online.vue'),
    meta: {
      title: '在线用户',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  
  // 日志管理路由
  {
    path: '/log/login',
    name: 'LoginLog',
    component: () => import('@/views/log/LoginLog.vue'),
    meta: {
      title: '登录日志',
      requiresAuth: true,
      requiresAdmin: true,
      keepAlive: false
    }
  },
  
  // 问卷管理路由
  {
    path: '/questionnaire/template-list',
    name: 'QuestionnaireTemplateList',
    component: () => import('@/views/questionnaire/TemplateList.vue'),
    meta: {
      title: '问卷模板管理',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  {
    path: '/questionnaire/template-edit/:id?',
    name: 'QuestionnaireTemplateEdit',
    component: () => import('@/views/questionnaire/TemplateEdit.vue'),
    meta: {
      title: '编辑问卷模板',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  {
    path: '/questionnaire/fill/:eventId',
    name: 'FillQuestionnaire',
    component: () => import('@/views/questionnaire/FillQuestionnaire.vue'),
    meta: {
      title: '填写问卷',
      requiresAuth: true
    }
  },
  {
    path: '/questionnaire/user-submissions',
    name: 'UserQuestionnaireSubmissions',
    component: () => import('@/views/questionnaire/UserSubmissions.vue'),
    meta: {
      title: '用户问卷提交记录',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  
  // 报表统计路由
  {
    path: '/report/dashboard',
    name: 'ReportDashboard',
    component: () => import('@/views/report/Dashboard.vue'),
    meta: {
      title: '统计概览',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  {
    path: '/report/user-ranking',
    name: 'UserRanking',
    component: () => import('@/views/report/UserRanking.vue'),
    meta: {
      title: '用户活跃度排行',
      requiresAuth: true,
      requiresAdmin: true
    }
  },
  
  // 错误页面
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/error/403.vue'),
    meta: { title: '403', requiresAuth: false }
  },
  {
    path: '/:pathMatch(.*)*',
    name: '404',
    component: () => import('@/views/error/404.vue'),
    meta: { title: '404', requiresAuth: false }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router 